package vj.hacker;

import java.util.*;

public class Solution {

    public static void main(String[] args) {
      Scanner in = new Scanner(System.in);
      int N = Integer.parseInt(in.nextLine());
      int moves[] = new int[N + 1];
      for(int i = 0; i < N; i++) {
        System.out.println(i);
        String count = in.nextLine();
        String snakes = in.nextLine();
        String ladders = in.nextLine();
        System.out.println(snakes);
        System.out.println(ladders);
        String snakePos[] = snakes.split(" ");
        String ladderPos[] = ladders.split(" ");
        /*for(int j = 0; j < snakePos.length; j++) {
          int pos[] = new int[2];
          pos[0] = Integer.parseInt(snakePos[j].split(" ")[0]);
          pos[1] = Integer.parseInt(snakePos[j].split(" ")[1]);
          moves[pos[0]] = pos[1];
        }
        for(int j = 0; j < ladderPos.length; j++) {
          int pos[] = new int[2];
          pos[0] = Integer.parseInt(ladderPos[j].split(" ")[0]);
          pos[1] = Integer.parseInt(ladderPos[j].split(" ")[1]);
          moves[pos[0]] = pos[1];
        }*/
      }
      for(int k =1 ;k <= moves.length; k++) {
        System.out.println(moves[k]);
      }
      //String snakes[] = new String[N];
      //String ladders[] = new String[N];
      
    }
}